<?php

namespace Frieza\Modules\Totem\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Doraemon\model\Totem\Totems;

class RackTotem extends RowAction
{
    public $name = '上架徽章';
    const TOAST_ALERT = '是否要将该徽章上架?上架后该徽章将会在APP内展示?';

    public function handle($id)
    {
        $data['totem_status'] = Totems::STATUS_NORMAL;
        $result = Totems::updateData($data, ['id' => $id]);
        if ($result) {
            return $this->response()->success('上架徽章成功!')->refresh();
        }else{
            return $this->response()->error('上架失败,请稍后重试!!');
        }
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}
